package com.javachmapi.springbootmysqlmybatisredis.dao;

import com.javachmapi.springbootmysqlmybatisredis.entity.Customer;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface CustomerMapper {
    /**
     * 将id设置为主键返回
     * useGeneratedKeys设为true是表示使用jdbc的getGeneratedKeys方法来取出数据的主键值（默认为false）
     * keyProperty标记返回的主键值传递给某个具体的属性（本例是将返回的值重新封装给Id）
     * @param customer
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into customer(name, age,address) values(#{name}, #{age}, #{address})")
    int save(Customer customer);

    //根据编号查询用户
    @Select("select * from customer t where t.id = #{id}")
    Customer getById(Integer id);

    @Delete("delete from customer where id = #{id}")
    int delete(Integer id);

    @Update("update customer t set t.name=#{name},t.age=#{age},t.address=#{address} where t.id = #{id}")
    int update(Customer customer);

    @Select("select count(1) from customer t")
    int count(@Param("params") Map<String, Object> params);

    @Select("select * from customer t where id limit #{offset}, #{limit}")
    List<Customer> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

}
